﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MapTemplates.cs" company="DarkBone">
//   DarkBone
// </copyright>
// <summary>
//   The map data.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DarkBone.Engine.Collections
{
   using System;
   using System.Diagnostics;
   using System.Drawing;
   using System.Linq;

   /// <summary>
   /// The map data.
   /// </summary>
   public sealed class MapTemplates
   {
      #region Constants and Fields

      /// <summary>
      /// The items.
      /// </summary>
      private static MapTemplate[] templates;

      #endregion

      #region Constructors and Destructors

      /// <summary>
      /// Initializes a new instance of the <see cref="MapTemplates"/> class.
      /// </summary>
      public MapTemplates()
      {
         templates = new[]
            {
               new MapTemplate("EF5B60A7B951000853F2885CE484FADE5E532545", "Abyss", 1.114F, 1.039F, -58F, 15F), 
               new MapTemplate("28BD96E30DD2AAE581471BC34D8779FD7A0973EB", "Agria Valley", 0.978F, 1.035F, 9F, 12F), 
               new MapTemplate("DEC9349872C3352C5A2457DA5E24B2B681336F12", "Arakan Citadel", 1.025F, 1.02F, -15F, 5F), 
               new MapTemplate("06AFF4AAFF8810D443BADB9A766C627DD13DD286", "Arid Wastes", 1.135F, 1.037F, -69F, 13F), 
               new MapTemplate("B34486C1075EE46B4101E194C8B4ABDF980E1907", "Blistering Sands", 1.198F, 1.031F, -98F, 12F), 
               new MapTemplate("03653859CF2B90B141BB1BE439C13739E36E76B5", "Backwater Gulch", 0.987F, 1.03F, 6F, 8F), 
               new MapTemplate("63D5717C1661DABA7065BFCA3CFFFBC045987CE5", "Burial Grounds", 1.02F, 1.03F, -8F, 12F), 
               new MapTemplate("6C37336423625ADF47936F989D09A55E2637A912", "Cinder Fortress", 0.982F, 1.021F, 9F, 7F), 
               new MapTemplate("373F790433EC4715385EBBB790CFE1AE4F13C8A9", "Colony 426", 1.017F, 1.033F, -11F, 15F), 
               new MapTemplate("9A16EB057D18642D059B0813E87FD22E5DAFD660", "Crossfire", 0.802F, 1.028F, 98F, 12F), 
               new MapTemplate("5095DCD5EEF898001F002337613F2A2BC40A560A", "Debris Field", 1.028F, 1.028F, -12F, 11F), 
               new MapTemplate("75AE2D4CEEF358EB9F7E975EA402656CC5363AC8", "Delta Quadrant", 1.119F, 1.026F, -59F, 11F), 
               new MapTemplate("27116FFE31D3C04476A6A054F7AB832E491805EB", "Desert Oasis", 0.982F, 1.035F, 8F, 14F), 
               new MapTemplate("017E4E0E94097ADF92765F0271469DC1E925DED3", "Dig Site", 0.981F, 1.031F, 9F, 10F), 
               new MapTemplate("06B0C3BD6EF10146838964F8316D6EBFB2DA7A14", "Discord IV", 0.985F, 1.032F, 7F, 13F), 
               new MapTemplate("EA2E9D231BD0FB5D9957A3D6D2B9308085C59829", "District 10", 1.076F, 1.028F, -39F, 9F), 
               new MapTemplate("79C6965F66D833EC480718C6FDAF75392C255E42", "Elysium", 1.081F, 1.036F, -41F, 14F), 
               new MapTemplate("E6E8312077594CCBF202B7781D6FFFE622527FD8", "Extinction", 0.978F, 1.021F, 10F, 7F), 
               new MapTemplate("C5947B01255E9895FBCD1FED559B4F7457ED84C2", "Forbidden Planet", 1.069F, 1.034F, -37F, 13F), 
               new MapTemplate("FF2F98E0EFD14B2254F2C1ECDE235646DB29473C", "Frontier", 1.057F, 1.02F, -29F, 7F), 
               new MapTemplate("E2F26955085C7860E23823E57CA954EEC928CB03", "Gutterhulk", 0.984F, 1.035F, 8F, 11F), 
               new MapTemplate("6DF4F09043FCB828A84055CB83B69BE5130D2437", "High Ground", 1.035F, 1.024F, -17F, 5F), 
               new MapTemplate("AC18E14B032703272BEB4C23FA59C8D5BDF10A4E", "High Orbit", 1.085F, 1.037F, -43F, 18F), 
               new MapTemplate("8C100E51E976BC81D9225A0793A357988F50784D", "Incineration Zone", 1.032F, 1.043F, -18F, 15F), 
               new MapTemplate("D4D34CF114AE160DC622684D30F9837974312090", "Jungle Basin", 0.784F, 1.033F, 108F, 9F), 
               new MapTemplate("0D015DB02A39052ACF6143BF0E30660F87441D5D", "Junk Yard", 1.037F, 1.048F, -20F, 21F), 
               new MapTemplate("5B69016C7D37D2B505443F781D3FEB3627273BE0", "Khaydarin Depths", 1.039F, 1.033F, -18F, 13F), 
               new MapTemplate("BC55467F86A2782F55FFCF1F28B5F395828B7A0C", "Kulas Ravine", 1F, 1F, 0F, 0F), 
               new MapTemplate("4AFD8D87709A7AB2D87157226613FFD3D32C5537", "Lava Flow", 0.918F, 1.028F, 42F, 11F), 
               new MapTemplate("DCE4DB62B950DB14FB28757F004B084CB796D7A0", "Lost Temple", 1.021F, 1.015F, -9F, 5F), 
               new MapTemplate("2C38196D8EEEAB2C39B3696728CF19F256B465F0", "Megaton", 1.203F, 1.03F, -104F, 11F), 
               new MapTemplate("507DFD4427E7822D79E72325BA639D7F6A2D3392", "Metalopolis", 0.977F, 1.027F, 9F, 9F), 
               new MapTemplate("5101EC4010631F5A86E2AB99479024835535E740", "Monlyth Ridge", 0.985F, 1.033F, 7F, 11F), 
               new MapTemplate("04E2690E9D9BA2ABFAD3B62E1A29AD8F693E3B37", "Monsoon", 0.805F, 1.022F, 96F, 7F), 
               new MapTemplate("BC55467F86A2782F55FFCF1F28B5F395828B7A0C", "Kulas Ravine", 1.02F, 1.024F, -10F, 8F), 
               new MapTemplate("9323F6C8826FF080F0C90DF3FF66F51F694ED015", "Nightmare", 1.093F, 1.041F, -47F, 17F), 
               new MapTemplate("EEEA203E5FE56C7115DA635048CE4C97B8DA3DD0", "Omega Sector", 0.856F, 1.025F, 72F, 10F), 
               new MapTemplate("21705FC0A7F051EBB58EF40956288A219EA5F7BF", "Outpost", 1.193F, 1.03F, -95F, 8F), 
               new MapTemplate("03D56FBF1CBF163699BCCFD0D26E9515BB7BE7BD", "Quicksand", 1.006F, 1.008F, -4F, 2F), 
               new MapTemplate("4593196A20020B5C55A3BA0762BC0DD8F9130473", "Red Stone Gulch", 1.075F, 1.032F, -37F, 14F), 
               new MapTemplate("6496F8E86E89ABAF53E784D228CD21B4710C28A5", "Sand Canyon", 1.007F, 0.805F, 2F, -103F), 
               new MapTemplate("C5014845700147C81CFBECB42934C29ABAE0D012", "Scorched Haven", 1.035F, 0.821F, -18F, -93F), 
               new MapTemplate("ACB4C4B4794E8A1D4771524387DF6D982810812F", "Scrap Station", 1.065F, 1.025F, -34F, 8F), 
               new MapTemplate("AF3F7BDD17C604BE56A4F049B0FD6840ADAC85B9", "Shakuras Plateau", 1.136F, 1.039F, -68F, 16F), 
               new MapTemplate("5D351E309D89511CC869AF574212CFE2EE17CA68", "Slag Pits", 0.983F, 1.025F, 8F, 9F), 
               new MapTemplate("80F968B30C5FF011CED9D30205279000D3303602", "Steppes of War", 1.087F, 1.035F, -44F, 13F), 
               new MapTemplate("70C84D798B2B3832D2AD26AF7071F4802DCBA8D3", "Tal'darim Altar LE", 1.033F, 1.037F, -20F, 14F), 
               new MapTemplate("0F785089AD3039904A0AAC56073933EF76948119", "Tarsonis Assault", 0.897F, 1.025F, 50F, 7F), 
               new MapTemplate("190D05DA87F9796CB67D65B4116C35DCE5AFCBC0", "Tectonic Rift", 0.979F, 1.025F, 9F, 8F), 
               new MapTemplate("F905D2D5C251CBDA2416EAE2DA361D91B333B449", "Tempest", 1.066F, 1.033F, -35F, 12F), 
               new MapTemplate("CE9789C8C987CBEEF984285246EF268256670D08", "Terminus", 1.072F, 1.029F, -36F, 10F), 
               new MapTemplate("902E380AA06FD1E248FB48AFD51FD692B1DD3CBB", "The Bio Lab", 1.102F, 1.032F, -51F, 10F), 
               new MapTemplate("1B1FDEF8945F91FAA9C40F622C389848DF7DCB0A", "The Ruins of Tarsonis", 0.886F, 1.035F, 56F, 12F), 
               new MapTemplate("43C2DE2DAAD62243A9999FB7D1715B126FD07928", "The Shattered Temple", 1.026F, 1.009F, -15F, 0F), 
               new MapTemplate("CE33044C9AD1BB61D471E6312611F798F06BDFF3", "Toxic Slums", 0.986F, 1.024F, 8F, 8F), 
               new MapTemplate("1118719EFF5498FC1A50831C5686EFE937EBF8D5", "Twilight Fortress", 1.079F, 1.035F, -40F, 15F), 
               new MapTemplate("4233F2E2B595981A19C4C4906D31E2962D2E433F", "Typhon", 1.107F, 1.026F, -53F, 10F), 
               new MapTemplate("AC3D872A823D9992C55F7F33EB1B330FF45440AD", "Typhon Peaks", 1.045F, 1.045F, -22F, 18F), 
               new MapTemplate("85263EFC766E0F2424F2B92889C6B0A1A8DFF3D1", "Ulaan Deeps", 0.983F, 1.026F, 10F, 10F), 
               new MapTemplate("F7139C21795E3CF1C292C283ADA4CFB81EFB5D95", "War Zone", 0.893F, 1.004F, 52F, 0F), 
               new MapTemplate("72993FEFCA3EF3D5593AF76E9A2536B3738312F8", "Worldship", 1.118F, 1.03F, -61F, 13F), 
               new MapTemplate("AC0E100C1B232FE450453897034ABC41C895E696", "Xel'Naga Caverns", 1.095F, 1.034F, -49F, 10F), 
               new MapTemplate("A0152006632B97CBDE8BE4397BC0BBF649954CC2", "Zenith", 1.119F, 1.029F, -62F, 11F), 
            };
      }

      /// <summary>
      /// Gets the template.
      /// </summary>
      /// <param name="hash">The hash.</param>
      /// <returns>Map template</returns>
      public static MapTemplate GetTemplate(string hash)
      {
         foreach (var t in templates)
         {
            if (t.HashCode != hash)
            {
               continue;
            }

            var imagefilename = @"Assets\Maps\" + t.Filename + ".jpg";
            try
            {
               Debug.WriteLine("Loading background " + imagefilename);
               t.Background = Image.FromFile(imagefilename);
            }
            catch (Exception ex)
            {
               Debug.WriteLine("Hash: " + hash);
               Debug.WriteLine("Loading background failed: " + ex.Message);
               t.Background = new Bitmap(1000, 1000);
            }

            return t;
         }

         return new MapTemplate(hash, "unknown", 1, 1, 0, 0);
      }

      /// <summary>
      /// Gets the template.
      /// </summary>
      /// <param name="mapName">Name of the map.</param>
      /// <returns>
      /// Map template
      /// </returns>
      public static MapTemplate GetTemplateByMapName(string mapName)
      {
         foreach (var t in templates)
         {
            if (t.Filename != mapName)
            {
               continue;
            }

            var imagefilename = @"Assets\Maps\" + t.Filename + ".jpg";
            try
            {
               Debug.WriteLine("Loading background " + imagefilename);
               t.Background = Image.FromFile(imagefilename);
            }
            catch (Exception ex)
            {
               Debug.WriteLine("Map: " + mapName);
               Debug.WriteLine("Loading background failed: " + ex.Message);
               t.Background = new Bitmap(1000, 1000);
            }

            return t;
         }

         return new MapTemplate("unknown", mapName, 1, 1, 0, 0);
      }


      #endregion
   }
}